package design;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_yizYa
 * Date: 2025/8/31
 * Time: 18:49
 */
// 抽象类
abstract class Beverage {
    // 模板方法
    public final void prepareRecipe() {
        boilWater();
        getCondiment();
        putCondiment();
        putWaterToCup();
    }

    // 具体方法
    private void boilWater() {
        System.out.println("Boiling water");
    }

    // 抽象方法
    protected abstract void getCondiment();

    protected abstract void putCondiment();

    private void putWaterToCup() {
        System.out.println("Pouring into cup");
    }
}
class Tea extends Beverage {

    @Override
    protected void getCondiment() {
        System.out.println("从茶罐里取茶");
    }

    @Override
    protected void putCondiment() {
        System.out.println("将茶放入杯子中");
    }
}

class Coffee extends Beverage {

    @Override
    protected void getCondiment() {
        System.out.println("从咖啡罐中取咖啡");
    }

    @Override
    protected void putCondiment() {
        System.out.println("将咖啡放入杯子中");
    }
}

// 使用示例
public class TemplatePatternDemo {
    public static void main(String[] args) {
        Beverage tea = new Tea();
        tea.prepareRecipe();

        Beverage coffee = new Coffee();
        coffee.prepareRecipe();
    }
}
